//index.js
import http from "../../../class/Utils/Http"
import tips from "../../../class/Utils/Tips"
import user from "../../../class/Utils/User"
Page({
    data: {
        typemenuid: '1',
        liuyantag: false,
        selecthangye: false,
        list: [],
        headheight: '0',
        scrollNow: 0,
        chakan: false,

    },
    goto_card_huoban:function (e) {
        var that = this
        var friend_login = e.currentTarget.dataset.friend_login
        var card_id = e.currentTarget.dataset.card_id
        http.req("/Mingpian/pd_card_id",{friend_login:friend_login,card_id:card_id},function (res) {
            if(res.code ==200){
                tips.goto("/pages/mingpian/card/card?id=" + res.mingpianid);
            }else{
                tips.error("暂无名片")
            }
        })
    },
    onLoad: function () {
        var that = this

        var alphabit = []
        for (var i = 65; i < 91; i++) {
            alphabit.push(String.fromCharCode(i))
        }
        alphabit.push("#")
        that.setData({
            alphabit: alphabit
        })
        that.Huoquheadheight()
        that.listlist(that)

    },
    chakan: function (e) {
        var that = this
        var index = e.currentTarget.dataset.index
        var idx = e.currentTarget.dataset.idx
        var list = that.data.list
        that.setData({
            info:list[idx][index],
            chakan:true
        })
    },
    guanbi: function () {
        this.setData({
            chakan: !this.data.chakan
        })
    },
    listlist: function (that) {
        var user = wx.getStorageSync('user')
        var data = {
            uid: user.userid
        }
        http.reqload("/Api/haoyou_list", data, function (res) {
            //console.log(res)
            //console.log(res.list.length)
            if(res.list.length <1){
                that.setData({
                    nodata: true
                })
            }
            that.setData({
                list: res.list
            })
        })
    },
    /*
     删除收藏
     */
    del: function (e) {
        var that = this
        var user = wx.getStorageSync("user")
        var id = e.currentTarget.dataset.id
        var name = e.currentTarget.dataset.name
        var index = e.currentTarget.dataset.index
        tips.modal("是否删除好友", true, 'function', false, function () {
            var data = {
                uid: user.userid,
                id: id,
                poster: name
            }

            http.req("/Api/haoyou_del", data, function (res) {
                if (res.code == '220') {
                    tips.ok(res.msg_val)
                    that.listlist(that)
                } else {
                    tips.error(res.msg_val)
                }
            })
        })
    },
    //圈成员字母查找
    zimuscroll: function (e) {
        var that = this
        var thiszimu = e.currentTarget.dataset.zimu

        //console.log(thiszimu)

      if (thiszimu == '#')
        thiszimu = ''


        //获取当前选择字母的节点 begin
        wx.createSelectorQuery().selectAll('.zimu' + thiszimu).boundingClientRect(function (rects) {

            rects.forEach(function (rect) {
                var zimujuli = rect.top

                var dataheadheight = that.data.headheight


                //console.log(zimujuli)
                //console.log(dataheadheight)
                var scrollweizhi = zimujuli - dataheadheight

                wx.pageScrollTo({
                    scrollTop: scrollweizhi + that.data.scrollNow,
                })
            })
        }).exec()
        //获取当前选择字母的节点 end


    },
    //获取顶部高度
    Huoquheadheight: function () {
        var that = this
        wx.createSelectorQuery().selectAll('.el-shangji-head').boundingClientRect(function (rects) {
            rects.forEach(function (rect) {
                that.setData({
                    headheight: rect.height
                })
            })
        }).exec()
    },
  onPageScroll: function (res) {
    var that = this;
    var topscroll = res.scrollTop;
    //console.log(topscroll)
    this.setData({

      scrollNow: topscroll

    })
  },
  /*
     点击名片
     */
    mingpian:function (e) {
        var that = this
        user.log_user(this, function (res) {
            var poster = e.currentTarget.dataset.poster
            var cid = e.currentTarget.dataset.cid
            if(cid){
                var dd ={
                    poster:poster,
                    cid:cid
                }
                //console.log(dd)
                http.reqload("/Api/mingpian",dd,function (res) {
                    //console.log(res)
                    if(res.code == 200){
                        tips.goto('/pages/mingpian/card/card?id='+res.mid)
                    }else{
                        tips.error(res.msg_val)
                    }
                })
            }else{
                tips.error("暂无名片")
            }

        })
    },

})
